package com.stork.sms.fragment;


import com.stork.sms.R;
import com.stork.sms.activity.Login;

import android.app.Fragment;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class ForgetPasswordFragment extends Fragment implements OnClickListener{

	Button SubmitButton;
	EditText ForgetUserName,Emailid;
	String s1="abc", s2="abc@gmail.com",a,b;
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		
		View view=inflater.inflate(R.layout.forgetpassword, null);	
		SubmitButton=(Button)view.findViewById(R.id.submitbutton);
		ForgetUserName=(EditText)view.findViewById(R.id.fusername);
		Emailid=(EditText)view.findViewById(R.id.emailid);
		Emailid.setVisibility(View.INVISIBLE);
		SubmitButton.setOnClickListener(this);
		return view;
	}
	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		
		a=ForgetUserName.getText().toString().trim();
		b=Emailid.getText().toString().trim();		
		
		if(a.equals("") && b.equals(""))
		{
			Toast.makeText(getActivity(), "Enter the Username or Email Id", 2000).show();
		}
		else if(a.equals(s1) && b.equals(""))
		{
			Emailid.setError("Enter Email id");
			Emailid.requestFocus();
		
		}
		else if(a.equals("") && b.equals(s2))
		{
			ForgetUserName.setError("Enter Username");
			ForgetUserName.requestFocus();
		}
		else if(a.equals(s1) && !b.equals(s2))
		{
			Emailid.setError("Incorrect Email id");
			Emailid.requestFocus();
		}
		else if(!a.equals(s1) && b.equals(s2))
		{
			ForgetUserName.setError("Incorrect Username");
			ForgetUserName.requestFocus();
					
		}
		else if(!a.equals(s1) && !b.equals(s2))
		{
			
			ForgetUserName.requestFocus();
			Toast.makeText(getActivity(), "Invalid Username or Email id", 2000).show();			
	}
		else
	{
		Intent reload=new Intent(getActivity(), Login.class);
		startActivity(reload);
	}
	}
}
